package com.vue.back.vbd.sys.controller;

import com.vue.back.vbd.sys.entity.Dict;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/dict")
public class DictController {

    @PostMapping(value = "get",produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String,Object> get(@RequestBody Dict dict){
        Map<String,Object> result = new HashMap<String,Object>();
        dict.setType("字典类型");
        result.put("success",true);
        result.put("dict",dict);
        return result;
    }

    @PostMapping(value = "exit",produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String,Object> exit(@RequestBody Dict dict){
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("success",true);
        result.put("code",200);
        return result;
    }

    @PostMapping(value = "getDictList")
    public Map<String,Object> getDictList(@RequestBody Map<String,Object> params){
        System.out.println("-----"+params);
        int current = (int)params.get("current");
        int pageSize = (int)params.get("pageSize");
        int total = 30;
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("total",total);
        int start = (current-1) * pageSize + 1;
        int end = current*pageSize>=total?total:current*pageSize;
        List<Dict> dictList = new ArrayList<Dict>();
        for(int i=start;i<=end;i++){
            Dict dict = new Dict();
            dict.setId(i+"");
            dict.setCode("code"+i);
            dict.setText("text"+i);
            dict.setType("type"+i);
            dict.setValue("value"+i);
            dictList.add(dict);
        }
        result.put("list",dictList);
        result.put("code",200);
        return result;
    }

}
